<template>
	<view>
		<view class="notice-detail">
			<view class="notice-detail-title">
				{{noticeItem.name}}
			</view>
			<view class="mar-15-0">
				<view class="flex-start center color-gray">
					<u-icon name="clock" size="28"></u-icon>
					发布时间：{{noticeItem.createTime}}
				</view>
				<view class="flex-start center color-gray">
					<u-icon name="eye" size="28"></u-icon>
					浏览次数：{{noticeItem.times}}
				</view>
			</view>
			<view class="content">
				<image v-if="noticeItem.subName" :src="hostApi+noticeItem.subName"></image>
				<u-parse :html="noticeItem.describe"></u-parse>
			</view>


		</view>
		<view class="notice-bottom flex-end">
			<view class="start-center">
				<view class="notice-item" :class="noticeLikeItem.statusLikes==1?'color-blue':''" @click="handleLikes">
					<view class=" font-size-20">
						<u-icon name="thumb-up-fill"></u-icon>
					</view>
					<view class="font-size-10">点赞</view>
				</view>
				<view class="mar-0-10" :class="noticeLikeItem.statusCollects==1?'color-blue':''"
					@click="handleCollects">
					<view class=" font-size-20">
						<u-icon name="star-fill"></u-icon>
					</view>
					<view class="font-size-10">收藏</view>
				</view>
				<!-- <view class="mar-0-10" @click="handleForwards">
					<view class=" font-size-20">
						<u-icon name="share-fill"></u-icon>
					</view>
					<view class="font-size-10">转发</view>
				</view> -->
			</view>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	import {
		noticeSelect,
		noticeTimes,
		noticeSelectById,
		noticeLikes,
		noticeCollects,
		noticeForwards,
	} from '../../../api/notice'
	import {
		noticeLikeSelect,
	} from '../../../api/noticeLike'
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	const config = {
		link: 'http://www.qq.com', // 网址，默认使用window.location.href
		title: '标题', // 标题，默认读取document.title 
		desc: '分享描述', // 描述, 默认读取<meta name="description" content="desc" />
		imgUrl: 'http://backtonature.github.io/project/m-share/demo1.png', // 图片, 默认取网页中第一个img标签
		types: ['wx', 'wxline', 'qq', 'qzone', 'sina'], // 启用的社交分享,默认为全部启用
		infoMap: { // 针对不同平台设定不同分享内容
			wx: {
				link: '分享到微信的链接', // 覆盖分享到微信的链接
				title: '分享到微信的标题', // 覆盖分享到微信的标题
				desc: '分享到微信的描述', // 覆盖分享到微信的标题
				imgUrl: '分享到微信的图片链接' // 覆盖分享到微信的图片链接
			}
		},
		fnDoShare(type) {
			// 执行分享的回调，type为'wx', 'wxline', 'qq', 'qzone', 'sina'
		}
	};
	export default {
		data() {
			return {
				load: true,
				params: '',
				noticeItem: {},
				id: 0,
				scrollTop: 0,
				noticeLikeItem: {},
			}
		},
		computed: {
			...mapGetters(['userInfo', 'hostApi'])
		},
		onLoad(e) {
			this.noticeItem = JSON.parse(e.item)
			this.noticeItem.patId = this.userInfo.patId
			console.log(this.noticeItem)
			this.init()
		},
		mounted(e) {

		},
		methods: {
			init() {
				noticeTimes(this.noticeItem).then(res => {
					this.noticeItem.times = res[0].times
					this.selectNoticeLike()
				})
			},
			selectNoticeLike() {
				noticeLikeSelect({
					patId: this.noticeItem.patId,
					noticeId: this.noticeItem.id
				}).then(res => {
					if (res.length > 0) {
						this.noticeLikeItem = res[0]
					}
				})
			},
			handleLikes() {
				if (this.noticeLikeItem.statusLikes == 1) {
					this.noticeItem.num = -1
				} else {
					this.noticeItem.num = 1
				}
				noticeLikes(this.noticeItem).then(res => {
					this.selectNoticeLike()
				})
			},
			handleCollects() {
				if (this.noticeLikeItem.statusCollects == 1) {
					this.noticeItem.num = -1
				} else {
					this.noticeItem.num = 1
				}
				noticeCollects(this.noticeItem).then(res => {
					this.selectNoticeLike()
				})
			},
			handleForwards() {
				console.log(1)
				// this.noticeItem.num = 1
				// noticeForwards(this.noticeItem).then(res => {
				// 	this.selectNoticeLike()
				// })
				// Mshare.init(config);
				uni.$u.mpShare = {
					title: 'xxx', // 默认为小程序名称
					path: '/pages/index/welcome', // 默认为当前页面路径
					imageUrl: 'xxx' // 默认为当前页面的截图
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.notice-detail {
		height: calc(100vh - 60px);
		background-color: $uni-bg-color;
		padding: 16rpx;

		.notice-detail-title {
			font-size: 44rpx;
			justify-content: center;
			align-items: center;
			margin: 10px 0;
			font-weight: bold;
		}

		.content {
			padding: 0 10px;
			height: calc(100vh - 200px);
			overflow: auto;
		}

	}

	.notice-bottom {
		position: fixed;
		bottom: 0;
		width: 100%;
		padding: 0 20px;
		height: 60px;
		display: flex;
		align-items: center;
		box-shadow: 0 5px 15px rgb(171, 191, 254);
		background-color: white;

		.notice-item {
			text-align: center;
			// margin: 0 15px;
			padding: 0 20px;
		}
	}
</style>